package com.senior.atomic;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

public class LongAdderApiDemo {

    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();//LongAdder有个缺点，只能做加法
        longAdder.increment();
        System.out.println(longAdder.longValue());

        //就是按照我们函数数操作然后进行累加
        LongAccumulator longAccumulator = new LongAccumulator((x,y)->x*y,1);
        longAccumulator.accumulate(1); // 1*1=1
        longAccumulator.accumulate(2); // 1*2=2
        longAccumulator.accumulate(3);//  2*3=6
        System.out.println(longAccumulator.longValue());
    }


}
